package com.zyd.blog.personal.service.impl;

import com.zyd.blog.persistence.mapper.MerchantInfoMapper;
import com.zyd.blog.personal.service.MerchantInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author mfy
 */
@Service
public class MerchantInfoServiceImpl implements MerchantInfoService {

    @Resource
    private MerchantInfoMapper merchantInfoMapper;

    @Override
    public List<Map<String,Object>> queryMerchantInfoByCondition(Map<String,Object> merchantInfo){
        return merchantInfoMapper.queryMerchantInfoByCondition(merchantInfo);
    }

    @Override
    public Map<String,Object> queryMerchantInfoById(Long id){
        if(id == null){
            return new HashMap<>(0);
        }
        Map<String,Object> merchantInfoCondition = new HashMap<>(16);
        merchantInfoCondition.put("id",id);
        List<Map<String,Object>> merchantInfos = queryMerchantInfoByCondition(merchantInfoCondition);
        if(merchantInfos == null || merchantInfos.size() == 0){
            return new HashMap<>(0);
        }
        Map<String,Object> merchantInfo = merchantInfos.get(0);
        merchantInfo.remove("isDelete");
        merchantInfo.remove("updateTime");
        merchantInfo.remove("addTime");
        return merchantInfo;
    }

    @Override
    public Boolean addMerchantInfo(Map<String,Object> merchantInfo){
        merchantInfo.put("applyTime",(new Date()).getTime());
        merchantInfo.put("updateTime",(new Date()).getTime());
        merchantInfo.put("addTime",(new Date()).getTime());
        return merchantInfoMapper.addMerchantInfo(merchantInfo) > 0;
    }

    @Override
    public boolean updateMerchantInfo(Map<String,Object> condition){
        String id = "id";
        if(condition.get(id) == null){
            return false;
        }
        condition.put("updateTime",(new Date()).getTime());
        return merchantInfoMapper.updateMerchantInfo(condition) > 0;
    }

}
